package de.tabuma.ssoclient.logik;

import java.util.*;
import de.tabuma.ssoclient.entity.*;
import de.tabuma.lib.webservice.client.*;

/**
 *
 * @author alefen
 */
public class PrivilegFacade {
    public static String soapUrl = "https://tabumasso.appspot.com/webservice";
    public static int create(Privileg privileg, String ssoId) throws Exception {
        String methodName = "PrivilegService_create";
        String soapAction = "PrivilegService_create";

        Class returnType = Integer.class;
        Object params[] = {privileg, ssoId};

        Integer obj = (Integer) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        privileg.setId(obj.longValue());
        PrivilegHashFacade.put(privileg, ssoId);
        return obj;
    }

    public static void update(Privileg privileg, String ssoId) throws Exception {
        String methodName = "PrivilegService_update";
        String soapAction = "PrivilegService_update";

        Object params[] = {privileg, ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        PrivilegHashFacade.put(privileg, ssoId);
    }

    public static Privileg get(int id, String ssoId) throws Exception {
        String methodName = "PrivilegService_get";
        String soapAction = "PrivilegService_get";

        Class returnType = Privileg.class;
        Object params[] = {Integer.valueOf(id), ssoId};

        Privileg obj = PrivilegHashFacade.get(id, ssoId);
        if(obj==null) {
            obj = (Privileg) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        }
        return obj;
    }

    public static void remove(int id, String ssoId) throws Exception {
        String methodName = "PrivilegService_remove";
        String soapAction = "PrivilegService_remove";

        Object params[] = {Integer.valueOf(id), ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        PrivilegHashFacade.remove(id, ssoId);
    }

    public static List<Privileg> getList(int projectId, String ssoId) throws Exception {
        String methodName = "PrivilegService_getList";
        String soapAction = "PrivilegService_getList";

        Class returnType = List.class;
        Class returnType1 = Privileg.class;
        Object params[] = {Integer.valueOf(projectId), ssoId};

        List<Privileg> obj = PrivilegHashFacade.getList(ssoId);
        if(obj==null) {
            obj = (List<Privileg>) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, returnType1);
            PrivilegHashFacade.setList(obj, ssoId);
        }
        return obj;
    }
}
